home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume13 / font-browser / part02 < prev    next >
Encoding:
Text File  |  1991-07-05  |  38.2 KB  |  1,712 lines

  1. Path: uunet!olivea!oliveb!veritas!amdcad!sun!exodus!opal.cs.tu-berlin.de
  2. From: phade@opal.cs.tu-berlin.de (Frank Gadegast)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i077: X Font Browser, Part02/02
  5. Message-ID: <16340@exodus.Eng.Sun.COM>
  6. Date: 6 Jul 91 07:12:51 GMT
  7. References: <csx-13i076-font-browser@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1700
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: phade@opal.cs.tu-berlin.de (Frank Gadegast)
  13. Posting-number: Volume 13, Issue 77
  14. Archive-name: font-browser/part02
  15.  
  16.  
  17. Second part of xfbrows.
  18.  
  19. ------------------------------cut here----------------------------
  20. #!/bin/sh
  21. # This is a shell archive (produced by shar 3.49)
  22. # To extract the files from this archive, save it to a file, remove
  23. # everything above the "!/bin/sh" line above, and type "sh file_name".
  24. #
  25. # made 07/01/1991 09:35 UTC by phade@trick
  26. # Source directory /tmp_mnt/home/all/phade/SRC/Phade/xfb
  27. #
  28. # existing files will NOT be overwritten unless -c is specified
  29. #
  30. # This shar contains:
  31. # length  mode       name
  32. # ------ ---------- ------------------------------------------
  33. #   2346 -rw-r--r-- butt.c
  34. #   5203 -rw-r--r-- dialog.c
  35. #   4803 -rw-r--r-- dir.c
  36. #   2987 -rw-r--r-- list.c
  37. #   3221 -rw-r--r-- misc.c
  38. #   6971 -rw-r--r-- scrl.c
  39. #   8155 -rw-r--r-- xfbrows.c
  40. #
  41. # ============= butt.c ==============
  42. if test -f 'butt.c' -a X"$1" != X"-c"; then
  43.     echo 'x - skipping butt.c (File already exists)'
  44. else
  45. echo 'x - extracting butt.c (Text)'
  46. sed 's/^X//' << 'SHAR_EOF' > 'butt.c' &&
  47. X
  48. #include "xfbrows.h"
  49. #include "bitmaps.h"
  50. X
  51. void BTCreate (bp, win, x, y, w, h, str, fg, bg)
  52. BUTT *bp;
  53. Window win;
  54. int x, y, w, h;
  55. char *str;
  56. unsigned long fg, bg;
  57. {
  58. X    bp->win = win;
  59. X    bp->x = x;
  60. X    bp->y = y;
  61. X    bp->w = w;
  62. X    bp->h = h;
  63. X    bp->str = str;
  64. X    bp->fg = fg;
  65. X    bp->bg = bg;
  66. X    bp->lit = 0;
  67. X    bp->active = 1;
  68. X    bp->toggle = 0;
  69. }
  70. X
  71. void BTSetActive (bp, act)
  72. BUTT *bp;
  73. int act;
  74. {
  75. X    if (bp->active != act)
  76. X    {
  77. X        bp->active = act;
  78. X        BTRedraw (bp);
  79. X    }
  80. }
  81. X
  82. void BTRedraw (bp)
  83. BUTT *bp;
  84. {
  85. X    int x, y, w, h, r;
  86. X    XPoint poly [9];
  87. X
  88. X    x = bp->x;
  89. X    y=bp->y;
  90. X    w=bp->w;
  91. X    h=bp->h;
  92. X    r=3;
  93. X
  94. X    poly [0].x = x;
  95. X    poly [0].y = y+r;
  96. X    poly [1].x = x;
  97. X    poly [1].y = y+h-r;
  98. X    poly [2].x = x+r;
  99. X    poly [2].y = y+h;
  100. X    poly [3].x = x+w-r;
  101. X    poly [3].y = y+h;
  102. X    poly [4].x = x+w;
  103. X    poly [4].y = y+h-r;
  104. X    poly [5].x = x+w;
  105. X    poly [5].y = y+r;
  106. X    poly [6].x = x+w-r;
  107. X    poly [6].y = y;
  108. X    poly [7].x = x+r;
  109. X    poly [7].y = y;
  110. X    poly [8].x = x;
  111. X    poly [8].y = y+r;
  112. X
  113. X    if (!bp->active) bp->lit = 0;
  114. X
  115. X    if (bp->lit) XSetForeground (theDisp, theGC, bp->fg);
  116. X    else XSetForeground (theDisp, theGC, bp->bg);
  117. X    XFillPolygon (theDisp, bp->win, theGC, poly, 9, Convex, CoordModeOrigin);
  118. X
  119. X    XSetForeground (theDisp, theGC, bp->fg);
  120. X    XDrawLines (theDisp, bp->win, theGC, poly, 9, CoordModeOrigin);
  121. X
  122. X    if (!bp->active)
  123. X    {
  124. X        XSetFillStyle (theDisp, theGC, FillStippled);
  125. X        XSetStipple (theDisp, theGC, grayStip);
  126. X    }
  127. X
  128. X    if (bp->lit) XSetForeground (theDisp, theGC, bp->bg);
  129. X    else XSetForeground (theDisp, theGC, bp->fg);
  130. X    XDrawString (theDisp, bp->win, theGC, CENTERX (cfinfo, x+w/2, bp->str), 
  131. X        CENTERY (cfinfo, y+h/2), bp->str, strlen (bp->str));
  132. X
  133. X    if (!bp->active) XSetFillStyle (theDisp, theGC, FillSolid);
  134. }
  135. X
  136. int BTTrack (bp)
  137. BUTT *bp;
  138. {
  139. X    Window rW, cW;
  140. X    int x, y, rx, ry, rval, inval;
  141. X    unsigned int mask;
  142. X
  143. X    if (!bp->active) return 0;
  144. X
  145. X    bp->lit = !bp->lit;
  146. X    inval = bp->lit;
  147. X
  148. X    BTRedraw (bp);
  149. X    XFlush (theDisp);
  150. X    Timer (75);
  151. X
  152. X    while (XQueryPointer (theDisp, bp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
  153. X    {
  154. X        if (! (mask & Button1Mask)) break;
  155. X        if (bp->lit!=inval && PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h))
  156. X            bp->lit = inval;BTRedraw (bp);XFlush (theDisp);
  157. X        if (bp->lit==inval && !PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h))
  158. X            bp->lit = !inval;BTRedraw (bp);XFlush (theDisp);
  159. X    }
  160. X
  161. X    rval = (bp->lit == inval);
  162. X    if (bp->lit && !bp->toggle) 
  163. X    {
  164. X        bp->lit = 0;
  165. X        BTRedraw (bp);
  166. X        XFlush (theDisp);
  167. X    }
  168. X    return (rval);
  169. }
  170. X
  171. SHAR_EOF
  172. chmod 0644 butt.c ||
  173. echo 'restore of butt.c failed'
  174. Wc_c="`wc -c < 'butt.c'`"
  175. test 2346 -eq "$Wc_c" ||
  176.     echo 'butt.c: original size 2346, current size' "$Wc_c"
  177. fi
  178. # ============= dialog.c ==============
  179. if test -f 'dialog.c' -a X"$1" != X"-c"; then
  180.     echo 'x - skipping dialog.c (File already exists)'
  181. else
  182. echo 'x - extracting dialog.c (Text)'
  183. sed 's/^X//' << 'SHAR_EOF' > 'dialog.c' &&
  184. X
  185. #include "xfbrows.h"
  186. X
  187. int disWIDE, disHIGH;
  188. #define diaWIDE 470
  189. #define diaHIGH 105
  190. X
  191. #define drawstr1 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  192. #define drawstr2 "abcdefghijklmnopqrstuvwxyz"
  193. #define drawstr3 "1234567890[]\\;',./{}|:\"<>?"
  194. X
  195. static char title [40];
  196. static char *diacom, *dianame;
  197. static char diainfo[50];
  198. X
  199. int SimpleEventLoop ();
  200. X
  201. char *ShortCutName (name, width)
  202. char *name;
  203. int width;
  204. {
  205. X    char buf [MAXPATHLEN];
  206. X    char nam [MAXPATHLEN];
  207. X
  208. X    if (StringWidth (name) > width)
  209. X    {
  210. X        strcpy (buf, name);
  211. X        while (StringWidth (buf) > width) buf [strlen(buf)-3]= '\0';
  212. X        strcpy (nam, buf);
  213. X        strcat (nam, "...");
  214. X    }
  215. X    else strcpy (nam, name);
  216. X    return (nam);
  217. }
  218. X
  219. char *maketitle (t)
  220. char *t;
  221. {
  222. X    strcpy (title, PROGNAME);
  223. X    strcat (title, " ");
  224. X    strcat (title, t);
  225. X    title [0]= toupper (title [0]);
  226. }
  227. X
  228. void CreateDisW ()
  229. {
  230. X    int i, l;
  231. X
  232. X    maketitle ("Font");
  233. X    XSetForeground (theDisp, theGC, infofg);
  234. X    XSetBackground (theDisp, theGC, infobg);
  235. X    SetFonts ();
  236. X    sprintf (diainfo, "Ascent: %d   Decent: %d",
  237. X        ASCENT, DESCENT);
  238. X    disWIDE = StringWidth (drawstr1)+30;
  239. X    if ((i = StringWidth (drawstr2)+30) > disWIDE) disWIDE = i;
  240. X    if ((i = StringWidth (drawstr3)+30) > disWIDE) disWIDE = i;
  241. X    SetNormal ();
  242. X    l = StringWidth (diainfo) + 110;
  243. X    if (l > disWIDE) disWIDE = l;
  244. X    if (disWIDE > 570) disWIDE = 570;
  245. X    if (disWIDE < 200) disWIDE = 200;
  246. X    disHIGH = 80+3*LINEHIGH;
  247. X    if (disHIGH > 270) disHIGH = 270;
  248. X    disW = XCreateSimpleWindow (theDisp, dirW, (DIRWIDE-disWIDE)/2,
  249. X        (DIRHIGH-disHIGH)/2, disWIDE-4, disHIGH-4, 
  250. X        bwidth, infofg, infobg);
  251. X    if (!disW) FatalError ("can't create dispaly window");
  252. X    XSelectInput (theDisp, disW, ExposureMask | ButtonPressMask);
  253. X    BTCreate (&sbut [S_SOK], disW, disWIDE-80, disHIGH-34, BUTTW, BUTTH, 
  254. X        "Ok", infofg, infobg);
  255. X    XMapRaised (theDisp, disW);
  256. }
  257. X
  258. void RedrawDisW ()
  259. {
  260. X    char str1[50];
  261. X    char str2[50];
  262. X    char str3[50];
  263. X
  264. X    XSetForeground (theDisp, theGC, infofg);
  265. X    XSetBackground (theDisp, theGC, infobg);
  266. X    SetBold ();
  267. X    XDrawString (theDisp, disW, theGC, (disWIDE-StringWidth (title))/2, 
  268. X        15, title, strlen (title));
  269. X    SetNormal ();
  270. X    XDrawLine (theDisp, disW, theGC, 0, 20, disWIDE, 20);
  271. X    SetBold ();
  272. X    BTRedraw (&sbut [S_SOK]);
  273. X    SetNormal ();
  274. X    SetFonts ();
  275. X    strcpy (str1, drawstr1);
  276. X    strcpy (str2, drawstr2);
  277. X    strcpy (str3, drawstr3);
  278. X    if (dispWIDE = 570)
  279. X    {
  280. X        strcpy (str1, ShortCutName (drawstr1, 520));
  281. X        strcpy (str2, ShortCutName (drawstr2, 520));
  282. X        strcpy (str3, ShortCutName (drawstr3, 520));
  283. X    }
  284. X    XDrawString (theDisp, disW, theGC, 10, 30+LINEHIGH,
  285. X        str1, strlen (str1));
  286. X    if (disHIGH-70-LINEHIGH>LINEHIGH)
  287. X        XDrawString (theDisp, disW, theGC, 10, 30+2*LINEHIGH,
  288. X            str2, strlen (str2));
  289. X    if (disHIGH-70-2*LINEHIGH>LINEHIGH)
  290. X        XDrawString (theDisp, disW, theGC, 10, 30+3*LINEHIGH,
  291. X            str3, strlen (str3));
  292. X    SetNormal ();
  293. X    XDrawString (theDisp, disW, theGC, 10, disHIGH-20,
  294. X        diainfo, strlen (diainfo));
  295. X    XFlush (theDisp);
  296. }
  297. X
  298. int DisplayEventLoop ()
  299. {
  300. X    return (SimpleEventLoop (disW));
  301. }
  302. X
  303. void CreateDiaW (comment, name)
  304. char *comment, *name;
  305. {
  306. X    diacom = comment;
  307. X    dianame = ShortCutName (name, diaWIDE-30);
  308. X
  309. X    XSetForeground (theDisp, theGC, infofg);
  310. X    XSetBackground (theDisp, theGC, infobg);
  311. X    diaW = XCreateSimpleWindow (theDisp, dirW, (DIRWIDE-diaWIDE)/2,
  312. X        (DIRHIGH-diaHIGH)/2, diaWIDE-8, diaHIGH-8, 
  313. X        bwidth + 2, infofg, infobg);
  314. X    if (!diaW) FatalError ("can't create dialog window");
  315. X    XSelectInput (theDisp, diaW, ExposureMask | ButtonPressMask);
  316. X    BTCreate (&sbut [S_SOK], diaW, diaWIDE-80, diaHIGH-35, BUTTW, BUTTH, 
  317. X        "Ok", infofg, infobg);
  318. X    XMapRaised (theDisp, diaW);
  319. }
  320. X
  321. void RedrawDiaW ()
  322. {
  323. X    XSetForeground (theDisp, theGC, infofg);
  324. X    XSetBackground (theDisp, theGC, infobg);
  325. X    SetBold ();
  326. X    XDrawString (theDisp, diaW, theGC, (diaWIDE-StringWidth (title))/2, 
  327. X        15, title, strlen (title));
  328. X    SetNormal ();
  329. X    XDrawLine (theDisp, diaW, theGC, 0, 20, diaWIDE, 20);
  330. X    XDrawString (theDisp, diaW, theGC, 10, 40, diacom, strlen (diacom));
  331. X    XDrawString (theDisp, diaW, theGC, 10, 60, dianame, strlen (dianame));
  332. X    SetBold ();
  333. X    BTRedraw (&sbut [S_SOK]);
  334. X    SetNormal ();
  335. }
  336. X
  337. void CreateErrW (comment, name)
  338. char *comment, *name;
  339. {
  340. X    maketitle ("Error");
  341. X    CreateDiaW (comment, name);
  342. }
  343. X
  344. void RedrawErrW ()
  345. {
  346. X    RedrawDiaW ();
  347. X    XBell (theDisp, 0);
  348. }
  349. X
  350. int ErrorEventLoop ()
  351. {
  352. X    return (SimpleEventLoop (diaW));
  353. }
  354. X
  355. int SimpleEventLoop (win)
  356. Window win;
  357. {
  358. X    XEvent event;
  359. X    BUTT *bp;
  360. X    int end = 1;
  361. X    int ret = 0;
  362. X
  363. X    XSetForeground (theDisp, theGC, infofg);
  364. X    XSetBackground (theDisp, theGC, infobg);
  365. X    bp = &sbut [S_SOK];
  366. X
  367. X    XDefineCursor (theDisp, dirW, hand);
  368. X    XDefineCursor (theDisp, win, hand);
  369. X    while (end)
  370. X    {
  371. X        XNextEvent (theDisp, &event);
  372. X        switch (event.type)
  373. X        {
  374. X            case Expose:
  375. X                {
  376. X                    XExposeEvent *exp_event = (XExposeEvent *) &event;
  377. X
  378. X                    ExposureWin (exp_event);
  379. X                    if (exp_event->window == disW) RedrawDisW ();
  380. X                    else if (exp_event->window == diaW) RedrawDiaW ();
  381. X                }
  382. X                break;
  383. X            case ButtonPress:
  384. X                {
  385. X                XButtonEvent *b = (XButtonEvent *) &event;
  386. X                switch (b->button)
  387. X                {
  388. X                    case Button1: 
  389. X                        if (PTINRECT (b->x, b->y, bp->x, bp->y, bp->w, bp->h))
  390. X                            if (BTTrack (bp)) end = 0;
  391. X                        break;
  392. X                    default:
  393. X                        break;
  394. X                }
  395. X                }
  396. X                break;
  397. X            default :
  398. X                break;
  399. X        }
  400. X    }
  401. X    XDefineCursor (theDisp, dirW, arrow);
  402. X    XDestroyWindow (theDisp, win);
  403. X    return (ret);
  404. }
  405. X
  406. SHAR_EOF
  407. chmod 0644 dialog.c ||
  408. echo 'restore of dialog.c failed'
  409. Wc_c="`wc -c < 'dialog.c'`"
  410. test 5203 -eq "$Wc_c" ||
  411.     echo 'dialog.c: original size 5203, current size' "$Wc_c"
  412. fi
  413. # ============= dir.c ==============
  414. if test -f 'dir.c' -a X"$1" != X"-c"; then
  415.     echo 'x - skipping dir.c (File already exists)'
  416. else
  417. echo 'x - extracting dir.c (Text)'
  418. sed 's/^X//' << 'SHAR_EOF' > 'dir.c' &&
  419. X
  420. #include "xfbrows.h"
  421. #include "bitmaps.h"
  422. X
  423. #define MAXNAMES    10000
  424. X
  425. #define LISTW 565
  426. #define DDWIDE LISTW-80+15
  427. #define MAXDEEP 30
  428. #define MAXFNLEN 40
  429. #define DEFFILENAME ""
  430. X
  431. static int listh;
  432. static int numdirnames = 0;
  433. static int toomuchfonts = 0;
  434. static char filename [MAXPATHLEN];
  435. static char typename [MAXPATHLEN];
  436. X
  437. static void RedrawDList ();
  438. static int dnamcmp ();
  439. X
  440. void CreateDirW (geom)
  441. char *geom;
  442. {
  443. X    char message[50];
  444. X
  445. X    listh = LINEHIGH * NLINES;
  446. X
  447. X    dirW = CreateWindow (PROGNAME, geom, DIRWIDE, DIRHIGH, infofg, infobg);
  448. X    if (!dirW) FatalError ("couldn't create window!");
  449. X
  450. X    dnamW = XCreateSimpleWindow (theDisp, dirW, 10, listh+46-ASCENT, 
  451. X        510, LINEHIGH+4, 1, infofg, infobg);
  452. X    if (!dnamW) FatalError ("can't create window");
  453. X    XSelectInput (theDisp, dnamW, ExposureMask);
  454. X
  455. X    grayStip = XCreatePixmapFromBitmapData (theDisp, dirW, gray50_bits, 
  456. X        gray50_width, gray50_height, 1, 0, 1);
  457. X
  458. X    LSCreate (&dList, dirW, 10, LINEHIGH-5, LISTW, listh, NLINES, 
  459. X        dirnames, numdirnames, 
  460. X        infofg, infobg, RedrawDList, 1, 0);
  461. X
  462. X    BTCreate (&dbut [S_BQUIT], dirW, 530, listh+47-ASCENT, BUTTW, BUTTH, 
  463. X        "Quit", infofg, infobg);
  464. X
  465. X    SetTypeName (DEFFILENAME);
  466. X    LoadCurrentDirectory ();
  467. X    XMapSubwindows (theDisp, dirW);
  468. X    XSelectInput (theDisp, dirW, ExposureMask | ButtonPressMask | KeyPressMask);
  469. X    XMapRaised (theDisp, dirW);
  470. X    XDefineCursor (theDisp, dirW, arrow);
  471. X    if (toomuchfonts)
  472. X    {
  473. X        sprintf (message, "There are more than %d fonts !!!", MAXNAMES);
  474. X        CreateErrW (message, "Reconfigure and recompile !!!");
  475. X        RedrawErrW ();
  476. X        ErrorEventLoop ();
  477. X    }
  478. }
  479. void RedrawDirW (x, y, w, h)
  480. int x, y, w, h;
  481. {
  482. X    int ypos;
  483. X    char foo [30];
  484. X    XRectangle xr;
  485. X
  486. X    xr.x = x;
  487. X    xr.y = y;
  488. X    xr.width = w;
  489. X    xr.height = h;
  490. X    XSetClipRectangles (theDisp, theGC, 0, 0, &xr, 1, Unsorted);
  491. X
  492. X    ypos = 4 + ASCENT;
  493. X    XSetForeground (theDisp, theGC, infobg);
  494. X    XFillRectangle (theDisp, dirW, theGC, 10, ypos-ASCENT, DIRWIDE, CHIGH);
  495. X    XSetForeground (theDisp, theGC, infofg);
  496. X
  497. X    if (dList.nstr==1) strcpy (foo, "1 font");
  498. X    else sprintf (foo, "%d fonts", dList.nstr);
  499. X
  500. X    ypos = dList.y + dList.h + 5 + ASCENT;
  501. X    XSetForeground (theDisp, theGC, infobg);
  502. X    XFillRectangle (theDisp, dirW, theGC, 10, ypos-ASCENT, DIRWIDE, CHIGH);
  503. X    XSetForeground (theDisp, theGC, infofg);
  504. X    SetBold ();
  505. X    XDrawString (theDisp, dirW, theGC, 10, ypos, foo, strlen (foo));
  506. X    SetNormal ();
  507. X
  508. X    SetBold ();
  509. X    BTRedraw (&dbut [S_BQUIT]);
  510. X    SetNormal ();
  511. X
  512. X    XSetClipMask (theDisp, theGC, None);
  513. }
  514. X
  515. int ClickDirW (x, y)
  516. int x, y;
  517. {
  518. X    BUTT *bp;
  519. X    int bnum;
  520. X
  521. X    for (bnum=0;bnum<S_NBUTTS;bnum++)
  522. X    {
  523. X        bp = &dbut [bnum];
  524. X        if (PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h)) break;
  525. X    }
  526. X    if (bnum<S_NBUTTS) if (BTTrack (bp)) return (bnum);
  527. X    return -1;
  528. }
  529. X
  530. void SelectDir (n)
  531. int n;
  532. {
  533. X    SetDirFName (dList.str [n]);
  534. X    if ((disfinfo = XLoadQueryFont (theDisp, filename)) == NULL)
  535. X    {
  536. X        CreateErrW ("Unable to load font:", filename);
  537. X        RedrawErrW ();
  538. X        ErrorEventLoop ();
  539. X        return;
  540. X    }
  541. X    CreateDisW ();
  542. X    RedrawDisW ();
  543. X    DisplayEventLoop ();
  544. }
  545. X
  546. static void RedrawDList ()
  547. {
  548. X    LSRedraw (&dList);
  549. }
  550. X
  551. void SetFonts ()
  552. {
  553. X    disfont = disfinfo->fid;
  554. X    XSetForeground (theDisp, theGC, infofg);
  555. X    XSetBackground (theDisp, theGC, infobg);
  556. X    XSetFont (theDisp, theGC, disfont);
  557. X    cfinfo = disfinfo;
  558. }
  559. X
  560. void LoadCurrentDirectory ()
  561. {
  562. X    int i;
  563. X
  564. X    dirnames = XListFonts (theDisp, "*", MAXNAMES, &numdirnames);
  565. X    if (numdirnames == MAXNAMES) toomuchfonts = 1;
  566. X    qsort ((char *) dirnames, numdirnames, sizeof (char *), dnamcmp);
  567. X    LSNewData (&dList, dirnames, numdirnames);
  568. X    RedrawDirW (0, 0, DIRWIDE, DIRHIGH);
  569. X    SetDirFName (DEFFILENAME);
  570. }
  571. X
  572. static int dnamcmp (s1, s2)
  573. char **s1, **s2;
  574. {
  575. X    return (strcmp ((*s1), (*s2)));
  576. }
  577. X
  578. int DirKey (c)
  579. int c;
  580. {
  581. X    int len;
  582. X
  583. X    len = strlen (typename);
  584. X    if (c>' ' && c<'\177')
  585. X    {
  586. X        if (c=='/') return (-1);
  587. X        if (len >= MAXFNLEN-1) return (-1);
  588. X        typename [len]=c;
  589. X        typename [len+1]='\0';
  590. X    }
  591. X    else if (c=='\010' || c=='\177')
  592. X    {
  593. X        if (len==0) return (-1);
  594. X        typename [len-1]='\0';
  595. X    }
  596. X    else if (c=='\025') strcpy (typename, "");
  597. X    else if (c==13)
  598. X    {
  599. X        if (strlen (typename) == 0) return (-1);
  600. X        strcpy (filename, typename);
  601. X        if ((disfinfo = XLoadQueryFont (theDisp, filename)) == NULL)
  602. X        {
  603. X            CreateErrW ("Unable to load font:", filename);
  604. X            RedrawErrW ();
  605. X            ErrorEventLoop ();
  606. X            return (0);
  607. X        }
  608. X        CreateDisW ();
  609. X        RedrawDisW ();
  610. X        DisplayEventLoop ();
  611. X        strcpy (typename, "");
  612. X    }
  613. X    else return (-1);
  614. X
  615. X    SetTypeName (typename);
  616. X    return (0);
  617. }
  618. X
  619. void RedrawDNamW ()
  620. {
  621. X    int width, len;
  622. X
  623. X    len = strlen (typename);
  624. X    XSetForeground (theDisp, theGC, infofg);
  625. X    XDrawString (theDisp, dnamW, theGC, 3, ASCENT+3, typename, len);
  626. X    width = StringWidth (typename);
  627. X    XDrawLine (theDisp, dnamW, theGC, 3+width+1, 3, 3+width+1, 3+CHIGH);
  628. }
  629. X
  630. void SetDirFName (st)
  631. char *st;
  632. {
  633. X    strcpy (filename, st);
  634. }
  635. X
  636. void SetTypeName (st)
  637. char *st;
  638. {
  639. X    strcpy (typename, st);
  640. X    XClearWindow (theDisp, dnamW);
  641. X    RedrawDNamW ();
  642. }
  643. X
  644. SHAR_EOF
  645. chmod 0644 dir.c ||
  646. echo 'restore of dir.c failed'
  647. Wc_c="`wc -c < 'dir.c'`"
  648. test 4803 -eq "$Wc_c" ||
  649.     echo 'dir.c: original size 4803, current size' "$Wc_c"
  650. fi
  651. # ============= list.c ==============
  652. if test -f 'list.c' -a X"$1" != X"-c"; then
  653.     echo 'x - skipping list.c (File already exists)'
  654. else
  655. echo 'x - extracting list.c (Text)'
  656. sed 's/^X//' << 'SHAR_EOF' > 'list.c' &&
  657. X
  658. #include "xfbrows.h"
  659. #include "bitmaps.h"
  660. X
  661. #define DBLCLKTIME 500
  662. #define LISTW        330
  663. #define pixlineheight    13
  664. X
  665. #define INACTIVE(lptr, item) ((lptr)->filetypes && (lptr)->dirsonly && \
  666. X                  (item) >= 0 && (item) < (lptr)->nstr && \
  667. X                  (lptr)->str[(item)][0] != C_DIR && \
  668. X                  (lptr)->str[(item)][0] != C_LNK)
  669. X
  670. static void drawSel ();
  671. X
  672. void LSCreate (lp, win, x, y, w, h, nlines, strlist, nstr, fg, bg, fptr, 
  673. X    typ, donly)
  674. LIST *lp;
  675. Window win;
  676. int x, y, w, h, nlines, nstr, typ, donly;
  677. unsigned long fg, bg;
  678. char **strlist;
  679. void (*fptr) ();
  680. {
  681. X    lp->win = XCreateSimpleWindow (theDisp, win, x, y, w, h, 1, infofg, infobg);
  682. X    if (!lp->win) FatalError ("can't create list window!");
  683. X
  684. X    lp->x = x;
  685. X    lp->y = y; 
  686. X    lp->w = w;
  687. X    lp->h = h;
  688. X    lp->fg = fg;
  689. X    lp->bg = bg;
  690. X    lp->str = strlist;
  691. X    lp->nstr = nstr;
  692. X    lp->selected = 0;
  693. X    lp->nlines = nlines;
  694. X    lp->filetypes= typ;
  695. X    lp->dirsonly = donly;
  696. X
  697. X    XSelectInput (theDisp, lp->win, ExposureMask | ButtonPressMask
  698. X        | ButtonReleaseMask | Button1MotionMask | EnterWindowMask
  699. X        | LeaveWindowMask);
  700. X
  701. X    SCCreate (&lp->scrl, win, x+w, y, 1, h, 0, nstr-nlines, curname, nlines-1, 
  702. X        fg, bg, fptr);
  703. }
  704. X
  705. void LSNewData (lp, strlist, nstr)
  706. LIST *lp;
  707. char **strlist;
  708. int nstr;
  709. {
  710. X    lp->str = strlist;
  711. X    lp->nstr = nstr;
  712. X    lp->selected = 0;
  713. X    SCSetRange (&lp->scrl, 0, nstr - lp->nlines, 0, lp->nlines-1);
  714. }
  715. X
  716. static void drawSel (lp, j)
  717. LIST *lp;
  718. int j;
  719. {
  720. X    int i, inactive;
  721. X    unsigned long fg, bg;
  722. X
  723. X    inactive = INACTIVE (lp, j);
  724. X
  725. X    i = j - lp->scrl.val;
  726. X    if (i<0 || i>=lp->nlines) return;
  727. X
  728. X    if (j == lp->selected && !inactive && j<lp->nstr) 
  729. X    {
  730. X        fg = lp->bg;
  731. X        bg = lp->fg;
  732. X    }
  733. X    else
  734. X    {
  735. X        fg = lp->fg;
  736. X        bg = lp->bg;
  737. X    }
  738. X
  739. X    XSetForeground (theDisp, theGC, bg);
  740. X    XFillRectangle (theDisp, lp->win, theGC, 0, i*LINEHIGH, lp->w, LINEHIGH);
  741. X
  742. X    if (j>=0 && j<lp->nstr)
  743. X    {
  744. X        XSetForeground (theDisp, theGC, fg);
  745. X        XSetBackground (theDisp, theGC, bg);
  746. X
  747. X        if (!lp->filetypes) 
  748. X            XDrawString (theDisp, lp->win, theGC, 3, i*LINEHIGH + ASCENT + 1, 
  749. X                lp->str [j], strlen (lp->str [j]));
  750. X        else
  751. X        {
  752. X            XDrawString (theDisp, lp->win, theGC, 6, 
  753. X                i*LINEHIGH + ASCENT + 1, 
  754. X                lp->str [j], strlen (lp->str [j]));
  755. X        }
  756. X    }
  757. }
  758. X
  759. void LSRedraw (lp)
  760. LIST *lp;
  761. {
  762. X    int i;
  763. X
  764. X    for (i = lp->scrl.val;i < lp->scrl.val + lp->nlines;i++) drawSel (lp, i);
  765. }
  766. X
  767. int LSClick (lp, ev)
  768. LIST *lp;
  769. XXButtonEvent *ev;
  770. {
  771. X    Window rW, cW;
  772. X    int rx, ry, x, y, sel, oldsel;
  773. X    unsigned int mask;
  774. X    static Time lasttime=0;
  775. X    static int lastsel = -1;
  776. X
  777. X    x = ev->x;
  778. X    y = ev->y;
  779. X    sel = lp->scrl.val + y/LINEHIGH;
  780. X    if (sel >= lp->nstr) sel = lp->selected;
  781. X
  782. X    if (ev->time - lasttime < DBLCLKTIME && sel==lastsel 
  783. X        && (lp->scrl.val + y/LINEHIGH) < lp->nstr
  784. X        && !INACTIVE (lp, sel)) return (sel);
  785. X
  786. X    lasttime = ev->time;lastsel = sel;
  787. X
  788. X    if (sel != lp->selected)
  789. X    {
  790. X        oldsel = lp->selected;
  791. X        lp->selected = sel;
  792. X        drawSel (lp, sel);
  793. X        drawSel (lp, oldsel);
  794. X        XFlush (theDisp);
  795. X    }
  796. X
  797. X    while (XQueryPointer (theDisp, lp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
  798. X    {
  799. X        if (! (mask & Button1Mask)) break;
  800. X    }
  801. X
  802. X    return (sel);
  803. }
  804. X
  805. SHAR_EOF
  806. chmod 0644 list.c ||
  807. echo 'restore of list.c failed'
  808. Wc_c="`wc -c < 'list.c'`"
  809. test 2987 -eq "$Wc_c" ||
  810.     echo 'list.c: original size 2987, current size' "$Wc_c"
  811. fi
  812. # ============= misc.c ==============
  813. if test -f 'misc.c' -a X"$1" != X"-c"; then
  814.     echo 'x - skipping misc.c (File already exists)'
  815. else
  816. echo 'x - extracting misc.c (Text)'
  817. sed 's/^X//' << 'SHAR_EOF' > 'misc.c' &&
  818. X
  819. #define NEEDSTIME
  820. #include "xfbrows.h"
  821. X
  822. static int timerdone;
  823. X
  824. Window CreateWindow (name, geom, w, h, fg, bg)
  825. char *name, *geom;
  826. unsigned int w, h;
  827. unsigned long fg, bg;
  828. {
  829. X    Window win;
  830. X    XSetWindowAttributes xswa;
  831. X    unsigned int xswamask;
  832. X    XWMHints xwmh;
  833. X    XSizeHints hints;
  834. X    int i, x, y;
  835. X    int a, b;
  836. X
  837. X    x = y = 1;
  838. X    i = XParseGeometry (geom, &x, &y, &a, &b);
  839. X    if (i&XValue || i&YValue) hints.flags = USPosition;
  840. X    else hints.flags = PPosition;
  841. X
  842. X    hints.flags |= USSize;
  843. X
  844. X    if (i&XValue && i&XNegative) x = dispWIDE - w - abs (x);
  845. X    if (i&YValue && i&YNegative) y = dispHIGH - h - abs (y);
  846. X
  847. X    hints.x = x;
  848. X    hints.y = y;
  849. X    hints.width = w;
  850. X    hints.height = h;
  851. X    hints.min_width = w;
  852. X    hints.min_height = h;
  853. X    hints.max_width = w;
  854. X    hints.max_height = h;
  855. X    hints.flags |= PMaxSize | PMinSize;
  856. X
  857. X    xswa.background_pixel = bg;
  858. X    xswa.border_pixel = fg;
  859. X    xswamask = CWBackPixel | CWBorderPixel;
  860. X
  861. X    win = XCreateWindow (theDisp, rootW, x, y, w, h, 
  862. X        bwidth, CopyFromParent, CopyFromParent, 
  863. X        CopyFromParent, xswamask, &xswa);
  864. X    if (!win) return (win);
  865. X
  866. X    XSetStandardProperties (theDisp, win, name, name, None, NULL, 0, &hints);
  867. X
  868. X    xwmh.input = True;
  869. X    xwmh.flags = InputHint;
  870. X    if (icongeom)
  871. X    {
  872. X        i = XParseGeometry (icongeom, &x, &y, &a, &b);
  873. X        if ((i&XValue && i&XNegative) ||
  874. X            (i&YValue && i&YNegative))
  875. X                FatalError ("can't parse negativ icon position");
  876. X        if (i&XValue) xwmh.icon_x = x;
  877. X        if (i&YValue) xwmh.icon_y = y;
  878. X        xwmh.flags |= IconPositionHint;
  879. X    }
  880. X    if (iconic)
  881. X    {
  882. X        xwmh.flags |= StateHint;
  883. X        xwmh.initial_state = IconicState;
  884. X    }
  885. X
  886. X    XSetWMHints (theDisp, win, &xwmh);
  887. X
  888. X    return (win);
  889. }
  890. X
  891. void SetBold ()
  892. {
  893. X    XSetFont (theDisp, theGC, bfont);
  894. X    cfinfo = bfinfo;
  895. }
  896. X
  897. void SetNormal ()
  898. {
  899. X    XSetFont (theDisp, theGC, mfont);
  900. X    cfinfo = mfinfo;
  901. }
  902. X
  903. int StringWidth (str)
  904. char *str;
  905. {
  906. X    return (XTextWidth (cfinfo, str, strlen (str)));
  907. }
  908. void ExposureWin (exp_event)
  909. XXExposeEvent *exp_event;
  910. {
  911. X    if (exp_event->count>0 && exp_event->window != dirW) return;
  912. X    else if (exp_event->window == dirW) 
  913. X        RedrawDirW (exp_event->x, exp_event->y,
  914. X            exp_event->width, exp_event->height);
  915. X    else if (exp_event->window == dList.win) LSRedraw (&dList);
  916. X    else if (exp_event->window == dList.scrl.win) SCRedraw (&dList.scrl);
  917. X    else if (exp_event->window == dnamW) RedrawDNamW ();
  918. }
  919. X
  920. void FatalError (identifier)
  921. char *identifier;
  922. {
  923. X    fprintf (stderr, "%s: %s\n", cmd, identifier);
  924. X    Quit (-1);
  925. }
  926. X
  927. static void FreeMostResources ()
  928. {
  929. X    if (!theDisp) return;
  930. X    if (dirW) XDestroyWindow (theDisp, dirW);
  931. X    XFreeFontNames (dirnames);
  932. X    XFlush (theDisp);
  933. }
  934. X
  935. void Quit (i)
  936. int i;
  937. X    FreeMostResources ();
  938. X    exit (i);
  939. }
  940. X
  941. static void onalarm ()
  942. {
  943. X    timerdone=1;
  944. }
  945. X
  946. void Timer (n)
  947. int n;
  948. {
  949. X    long usec;
  950. X    struct itimerval it;
  951. X
  952. X    if (!n) return;
  953. X
  954. #ifdef SCO
  955. X    if (!n) return;
  956. X    nap (n);
  957. X    return;
  958. #else
  959. X
  960. #ifdef USLEEP
  961. X    usleep (n);
  962. X    return;
  963. #else
  964. X
  965. #ifdef NOTIMER
  966. X    return;
  967. #else
  968. X
  969. X    usec = (long) n * 1000;
  970. X    memset (&it, 0, sizeof (it));
  971. X    if (usec>=1000000L)
  972. X    {
  973. X        it.it_value.tv_sec = usec / 1000000L;
  974. X        usec %= 1000000L;
  975. X    }
  976. X
  977. X    it.it_value.tv_usec = usec;
  978. X    timerdone=0;
  979. X    signal (SIGALRM, onalarm);
  980. X    setitimer (ITIMER_REAL, &it, (struct itimerval *)0);
  981. X    while (1)
  982. X    {
  983. X        HOLD_SIG;
  984. X        if (timerdone) break;
  985. X        else PAUSE_SIG;
  986. X    }
  987. X    RELEASE_SIG;
  988. X    signal (SIGALRM, SIG_DFL);
  989. #endif
  990. #endif
  991. #endif
  992. }
  993. X
  994. SHAR_EOF
  995. chmod 0644 misc.c ||
  996. echo 'restore of misc.c failed'
  997. Wc_c="`wc -c < 'misc.c'`"
  998. test 3221 -eq "$Wc_c" ||
  999.     echo 'misc.c: original size 3221, current size' "$Wc_c"
  1000. fi
  1001. # ============= scrl.c ==============
  1002. if test -f 'scrl.c' -a X"$1" != X"-c"; then
  1003.     echo 'x - skipping scrl.c (File already exists)'
  1004. else
  1005. echo 'x - extracting scrl.c (Text)'
  1006. sed 's/^X//' << 'SHAR_EOF' > 'scrl.c' &&
  1007. X
  1008. #include "xfbrows.h"
  1009. #include "bitmaps.h"
  1010. X
  1011. #define UPLINE 0
  1012. #define UPPAGE 1
  1013. #define DNLINE 2
  1014. #define DNPAGE 3
  1015. #define THUMB 4
  1016. #define SCRLWAIT 150
  1017. X
  1018. static Pixmap upPix, downPix;
  1019. static Pixmap up1Pix, down1Pix;
  1020. static Pixmap sgray;
  1021. static int pixmaps_built=0;
  1022. X
  1023. static int whereInScrl ();
  1024. static void drawArrow ();
  1025. X
  1026. void SCCreate (sp, parent, x, y, vert, len, minv, maxv, curv, page, 
  1027. X    fg, bg, func)
  1028. SCRL *sp;
  1029. Window parent;
  1030. int x, y, vert, len, minv, maxv, curv, page;
  1031. unsigned long fg, bg;
  1032. void (*func) ();
  1033. {
  1034. X    if (!pixmaps_built)
  1035. X    {
  1036. X        upPix = XCreatePixmapFromBitmapData (theDisp, parent, 
  1037. X            up_bits, up_width, up_height, fg, bg, dispDEEP);
  1038. X        downPix = XCreatePixmapFromBitmapData (theDisp, parent, 
  1039. X            down_bits, down_width, down_height, fg, bg, dispDEEP);
  1040. X        up1Pix = XCreatePixmapFromBitmapData (theDisp, parent, 
  1041. X            up1_bits, up1_width, up1_height, fg, bg, dispDEEP);
  1042. X        down1Pix = XCreatePixmapFromBitmapData (theDisp, parent, 
  1043. X            down1_bits, down1_width, down1_height, fg, bg, dispDEEP);
  1044. X        sgray = XCreatePixmapFromBitmapData (theDisp, parent, 
  1045. X            scrlgray_bits, scrlgray_width, scrlgray_height, fg, bg, dispDEEP);
  1046. X    }
  1047. X
  1048. X    sp->vert = vert;
  1049. X    sp->len = len;
  1050. X    sp->fg = fg;
  1051. X    sp->bg = bg;
  1052. X    sp->uplit = sp->dnlit = 0;
  1053. X
  1054. X    if (vert) 
  1055. X        sp->win = XCreateSimpleWindow (theDisp, parent, x, y, up_width-2,
  1056. X            len, 1, fg, bg);
  1057. X    else FatalError ("don't know HOW to make horizontal scrollbar");
  1058. X
  1059. X    if (!sp->win) FatalError ("can't create scrollbar window");
  1060. X
  1061. X    sp->tsize = up_width-2;
  1062. X    sp->tmin = up_height-1;
  1063. X    sp->tmax = len - (up_height-1) - sp->tsize;
  1064. X    sp->drawobj = func;
  1065. X
  1066. X    SCSetRange (sp, minv, maxv, curv, page);
  1067. X    XSelectInput (theDisp, sp->win, ExposureMask | ButtonPressMask);
  1068. }
  1069. X
  1070. void SCSetRange (sp, minv, maxv, curv, page)
  1071. SCRL *sp;
  1072. int minv, maxv, curv, page;
  1073. {
  1074. X    if (maxv<minv) maxv=minv;
  1075. X    sp->min = minv;
  1076. X    sp->max = maxv;
  1077. X    sp->page = page;
  1078. X    sp->active = (minv < maxv);
  1079. X
  1080. X    if (sp->active) XSetWindowBackgroundPixmap (theDisp, sp->win, sgray);
  1081. X    else XSetWindowBackground (theDisp, sp->win, sp->bg);
  1082. X
  1083. X    SCSetVal (sp, curv);
  1084. }
  1085. X
  1086. void SCSetVal (sp, curv)
  1087. SCRL *sp;
  1088. int curv;
  1089. {
  1090. X    RANGE (curv, sp->min, sp->max);
  1091. X    sp->val = curv;
  1092. X
  1093. X    if (sp->active) 
  1094. X        sp->tpos = sp->tmin + ((sp->tmax - sp->tmin)* (curv - sp->min))
  1095. X            / (sp->max - sp->min);
  1096. X    SCRedraw (sp);
  1097. X    (sp->drawobj) ();
  1098. X    XFlush (theDisp);
  1099. }
  1100. X
  1101. void SCRedraw (sp)
  1102. SCRL *sp;
  1103. {
  1104. X    XSetForeground (theDisp, theGC, sp->fg);
  1105. X    XSetBackground (theDisp, theGC, sp->bg);
  1106. X
  1107. X    XClearWindow (theDisp, sp->win);
  1108. X    if (sp->vert)
  1109. X    {
  1110. X        drawArrow (sp, UPLINE);
  1111. X        drawArrow (sp, DNLINE);
  1112. X
  1113. X        if (sp->active)
  1114. X        {
  1115. X            XSetForeground (theDisp, theGC, sp->bg);
  1116. X            XFillRectangle (theDisp, sp->win, theGC, 
  1117. X                1, sp->tpos+1, sp->tsize-2, sp->tsize-2);
  1118. X            XSetForeground (theDisp, theGC, sp->fg);
  1119. X            XDrawRectangle (theDisp, sp->win, theGC, 
  1120. X                0, sp->tpos, sp->tsize-1, sp->tsize-1);
  1121. X        }
  1122. X    }
  1123. }
  1124. X
  1125. static int whereInScrl (sp, x, y)
  1126. SCRL *sp;
  1127. int x, y;
  1128. {
  1129. X    int v;
  1130. X
  1131. X    v=0;
  1132. X    if (sp->vert)
  1133. X    {
  1134. X        if (x<0 || x>up_width-2 || y<0 || y>sp->len) return -1;
  1135. X        v = y;
  1136. X    }
  1137. X
  1138. X    if (v < sp->tmin) return UPLINE;
  1139. X    if (sp->active)
  1140. X    {
  1141. X        if (v < sp->tpos) return UPPAGE;
  1142. X        if (v < sp->tpos + sp->tsize) return THUMB;
  1143. X        if (v <= sp->tmax + sp->tsize) return DNPAGE;
  1144. X    }
  1145. X    if (v > sp->tmax+sp->tsize) return DNLINE;
  1146. X
  1147. X    return -1;
  1148. }
  1149. X
  1150. static void drawArrow (sp, arr)
  1151. SCRL *sp;
  1152. int arr;
  1153. {
  1154. X    if (arr == UPLINE)
  1155. X    {
  1156. X        if (sp->uplit) 
  1157. X            XCopyArea (theDisp, up1Pix, sp->win, theGC, 0, 0,
  1158. X                up_width, up_height, -1, -1);
  1159. X        else XCopyArea (theDisp, upPix, sp->win, theGC, 0, 0,
  1160. X                up_width, up_height, -1, -1);
  1161. X    }
  1162. X    else if (arr == DNLINE)
  1163. X    {
  1164. X        if (sp->dnlit) 
  1165. X            XCopyArea (theDisp, down1Pix, sp->win, theGC, 0, 0,
  1166. X                up_width, up_height, -1, sp->len- (up_height-1));
  1167. X        else XCopyArea (theDisp, downPix, sp->win, theGC, 0, 0,
  1168. X            up_width, up_height, -1, sp->len- (up_height-1));
  1169. X    }
  1170. X    XFlush (theDisp);
  1171. }
  1172. X
  1173. void SCTrack (sp, mx, my)
  1174. SCRL *sp;
  1175. int mx, my;
  1176. {
  1177. X    Window rW, cW;
  1178. X    int rx, ry, x, y, ipos, pos, lit, ty, tyoff, ty1;
  1179. X    unsigned int mask;
  1180. X
  1181. X    ty = tyoff = 0;
  1182. X
  1183. X    XSetForeground (theDisp, theGC, sp->fg);
  1184. X    XSetBackground (theDisp, theGC, sp->bg);
  1185. X
  1186. X    ipos = whereInScrl (sp, mx, my);
  1187. X    lit = 1;
  1188. X
  1189. X    switch (ipos)
  1190. X    {
  1191. X        case UPLINE:
  1192. X            sp->uplit = 1;
  1193. X            if (sp->val > sp->min) SCSetVal (sp, sp->val-1); 
  1194. X            Timer (SCRLWAIT);
  1195. X            break;
  1196. X        case DNLINE:
  1197. X            sp->dnlit = 1;
  1198. X            if (sp->val < sp->max) SCSetVal (sp, sp->val+1);
  1199. X            Timer (SCRLWAIT);
  1200. X            break;
  1201. X        case UPPAGE:
  1202. X            SCSetVal (sp, sp->val - sp->page);
  1203. X            break;
  1204. X        case DNPAGE:
  1205. X            SCSetVal (sp, sp->val + sp->page);
  1206. X            break;
  1207. X        case THUMB:
  1208. X            tyoff = sp->tpos - my;
  1209. X            ty = sp->tpos;
  1210. X            if (sp->fg == black)
  1211. X                XSetState (theDisp, theGC, sp->bg, sp->fg, GXinvert, 
  1212. X                    sp->fg ^ sp->bg);
  1213. X            else
  1214. X                XSetState (theDisp, theGC, sp->fg, sp->bg, GXinvert, 
  1215. X                    sp->fg ^ sp->bg);
  1216. X            XDrawRectangle (theDisp, sp->win, theGC, 
  1217. X                0, sp->tpos, sp->tsize-1, sp->tsize-1);
  1218. X            break;
  1219. X    }
  1220. X
  1221. X    while (XQueryPointer (theDisp, sp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
  1222. X    {
  1223. X        if (! (mask & Button1Mask)) break;
  1224. X        switch (ipos)
  1225. X        {
  1226. X            case THUMB:
  1227. X                if (x<-16 || x>16+sp->tsize)
  1228. X                {
  1229. X                    if (lit)
  1230. X                    {
  1231. X                        lit = 0;
  1232. X                        XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
  1233. X                            sp->tsize-1, sp->tsize-1);
  1234. X                    }
  1235. X                }
  1236. X                else
  1237. X                {
  1238. X                    if (!lit)
  1239. X                    {
  1240. X                        lit = 1;
  1241. X                        ty = y + tyoff;
  1242. X                        RANGE (ty, sp->tmin, sp->tmax);
  1243. X                        XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
  1244. X                            sp->tsize-1, sp->tsize-1);
  1245. X                    }
  1246. X                    else
  1247. X                    {
  1248. X                        ty1 = y+tyoff;
  1249. X                        RANGE (ty1, sp->tmin, sp->tmax);
  1250. X                        if (ty != ty1)
  1251. X                        {
  1252. X                            XDrawRectangle (theDisp, sp->win, theGC, 
  1253. X                                0, ty, sp->tsize-1, sp->tsize-1);
  1254. X                            ty = ty1;
  1255. X                            XDrawRectangle (theDisp, sp->win, theGC, 
  1256. X                                0, ty, sp->tsize-1, sp->tsize-1);
  1257. X                        }
  1258. X                    }
  1259. X                }
  1260. X            break;
  1261. X        case UPLINE:
  1262. X        case DNLINE:
  1263. X            pos = whereInScrl (sp, x, y);
  1264. X            if (pos == ipos)
  1265. X            {
  1266. X                if (!lit)
  1267. X                { 
  1268. X                    lit = 1;
  1269. X                    if (ipos == UPLINE)
  1270. X                    {
  1271. X                        sp->uplit = 1;
  1272. X                        drawArrow (sp, UPLINE);
  1273. X                    }
  1274. X                    else
  1275. X                    {
  1276. X                        sp->dnlit = 1;
  1277. X                        drawArrow (sp, DNLINE);
  1278. X                    }
  1279. X                }
  1280. X                else
  1281. X                {
  1282. X                    if (sp->val > sp->min && pos==UPLINE)
  1283. X                    {
  1284. X                        SCSetVal (sp, sp->val-1);
  1285. X                        Timer (SCRLWAIT);
  1286. X                    }
  1287. X                    else if (sp->val < sp->max && pos==DNLINE)
  1288. X                    {
  1289. X                        SCSetVal (sp, sp->val+1);
  1290. X                        Timer (SCRLWAIT);
  1291. X                    }
  1292. X                }
  1293. X            }
  1294. X            else
  1295. X            {
  1296. X                if (lit)
  1297. X                {
  1298. X                    lit = 0;
  1299. X                    if (ipos == UPLINE)
  1300. X                    {
  1301. X                        sp->uplit = 0;
  1302. X                        drawArrow (sp, UPLINE);
  1303. X                    }
  1304. X                    else
  1305. X                    {
  1306. X                        sp->dnlit = 0;
  1307. X                        drawArrow (sp, DNLINE);
  1308. X                    }
  1309. X                }
  1310. X            }
  1311. X            break;
  1312. X        }
  1313. X    }
  1314. X
  1315. X    if (ipos == THUMB)
  1316. X    {
  1317. X        if (lit)
  1318. X            XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
  1319. X                sp->tsize-1, sp->tsize-1);
  1320. X        XSetState (theDisp, theGC, sp->fg, sp->bg, GXcopy, AllPlanes);
  1321. X
  1322. X        if (lit && ty != sp->tpos)
  1323. X        {
  1324. X            int dt, dv;
  1325. X            dt = sp->tmax - sp->tmin;
  1326. X            dv = sp->max - sp->min;
  1327. X            SCSetVal (sp, sp->min + (dv* (ty - sp->tmin)+dt/2) / dt);
  1328. X        }
  1329. X    }
  1330. X
  1331. X    if (lit && ipos == UPLINE)
  1332. X    {
  1333. X        sp->uplit = 0;
  1334. X        drawArrow (sp, UPLINE);
  1335. X    }
  1336. X    if (lit && ipos == DNLINE)
  1337. X    {
  1338. X        sp->dnlit = 0;
  1339. X        drawArrow (sp, DNLINE);
  1340. X    }
  1341. }
  1342. X
  1343. SHAR_EOF
  1344. chmod 0644 scrl.c ||
  1345. echo 'restore of scrl.c failed'
  1346. Wc_c="`wc -c < 'scrl.c'`"
  1347. test 6971 -eq "$Wc_c" ||
  1348.     echo 'scrl.c: original size 6971, current size' "$Wc_c"
  1349. fi
  1350. # ============= xfbrows.c ==============
  1351. if test -f 'xfbrows.c' -a X"$1" != X"-c"; then
  1352.     echo 'x - skipping xfbrows.c (File already exists)'
  1353. else
  1354. echo 'x - extracting xfbrows.c (Text)'
  1355. sed 's/^X//' << 'SHAR_EOF' > 'xfbrows.c' &&
  1356. /* --- C ---
  1357. **********************************************************************
  1358. *
  1359. *    Filename        : Xfbrows
  1360. *    Description        : XWindow font browser
  1361. *
  1362. *    Last modified    : 1 April 1990
  1363. *    Version            : 2.0
  1364. *    Language        : C
  1365. *    For machine        : INTERACTIVE Unix
  1366. *    Status            : Ready to publish
  1367. *    Compile as        : Makefile
  1368. *
  1369. *    Programed by    : Phade
  1370. *    Developed by    : Phade Software
  1371. *    Contact            : phade@cs.tu-berlin.de
  1372. *
  1373. *    Copyright (c) 1991 by Phade Software
  1374. *
  1375. **********************************************************************
  1376. */
  1377. X
  1378. #define MAIN
  1379. #include "xfbrows.h"
  1380. #include <X11/Xatom.h>
  1381. X
  1382. #define QUIT -1
  1383. #define FONT "-*-helvetica-medium-r-*-*-12-*"
  1384. #define BFONT "-*-helvetica-bold-r-*-*-12-*"
  1385. X
  1386. /*    #define FONT "-*-courier-medium-r-*-*-12-*"
  1387. X    #define BFONT "-*-courier-bold-r-*-*-12-*"    */
  1388. X
  1389. /*    #define FONT "8x13"
  1390. X    #define BFONT "8x13bold"    */
  1391. X
  1392. static unsigned long rootbg, rootfg;
  1393. static char *maingeom = NULL;
  1394. X
  1395. static Atom __SWM_VROOT = None;
  1396. static char str [128];
  1397. static char *def_str;
  1398. static int def_int;
  1399. X
  1400. static void Syntax ();
  1401. static int EventLoop ();
  1402. static int rd_int ();
  1403. static int rd_str ();
  1404. static int rd_flag ();
  1405. X
  1406. int main (argc, argv)
  1407. int argc;
  1408. char *argv [];
  1409. {
  1410. X    int i;
  1411. X    char *display, *whitestr, *blackstr, *fgstr, *bgstr;
  1412. X    char *rootfgstr, *rootbgstr;
  1413. X
  1414. X    XColor ecdef;
  1415. X    Window rootReturn, parentReturn, *children;
  1416. X    unsigned int numChildren;
  1417. X
  1418. X    display = whitestr = blackstr = NULL;
  1419. X    fgstr = bgstr = rootfgstr = rootbgstr = NULL;
  1420. X    cmd = rindex (argv [0], '/');
  1421. X    if (!cmd) cmd = argv [0];
  1422. X    else cmd++;
  1423. X
  1424. X    ncols = -1;
  1425. X    mono = 0;
  1426. X    bwidth = 2;
  1427. X
  1428. X    dirW = disW = NULL;
  1429. X    icongeom = NULL;
  1430. X    iconic = 0;
  1431. X
  1432. X    curname = 0;
  1433. X
  1434. X    for (i=1;i<argc-1;i++)
  1435. X    {
  1436. X        if (!strncmp (argv [i], "-d", 2))
  1437. X        {
  1438. X            display = argv [++i];
  1439. X            break;
  1440. X        }
  1441. X    }
  1442. X
  1443. X    if ((theDisp=XOpenDisplay (display)) == NULL)
  1444. X    {
  1445. X        fprintf (stderr, "%s: Can't open display\n", argv [0]);
  1446. X        Quit (-1);
  1447. X    }
  1448. X
  1449. X    if (rd_str ("geometry")) maingeom = def_str;
  1450. X    if (rd_str ("icongeom")) icongeom = def_str;
  1451. X    if (rd_str ("background")) bgstr = def_str;
  1452. X    if (rd_str ("foreground")) fgstr = def_str;
  1453. X    if (rd_int ("borderWidth")) bwidth = def_int;
  1454. X    iconic = rd_flag ("iconic");
  1455. X    numnames = 0;
  1456. X    for (i=1;i<argc;i++)
  1457. X    {
  1458. X        if (argv [i][0]!= '-') Syntax ();
  1459. X        else if (!strncmp (argv [i], "-bg", 3))
  1460. X                { if (++i<argc) bgstr = argv [i]; }
  1461. X        else if (!strncmp (argv [i], "-bw", 3))
  1462. X                { if (++i<argc) bwidth=atoi (argv [i]); }
  1463. X        else if (!strncmp (argv [i], "-d", 2))
  1464. X                { if (++i<argc) display = argv [i]; }
  1465. X        else if (!strncmp (argv [i], "-fg", 3))
  1466. X                { if (++i<argc) fgstr = argv [i]; }
  1467. X        else if (!strncmp (argv [i], "-ge", 3))
  1468. X                { if (++i<argc) maingeom = argv [i]; }
  1469. X        else if (!strncmp (argv [i], "-icong", 6))
  1470. X                { if (++i<argc) icongeom = argv [i]; }
  1471. X        else if (!strncmp (argv [i], "-iconi", 6)) iconic = 1;
  1472. X        else Syntax ();
  1473. X    }
  1474. X    theScreen = DefaultScreen (theDisp);
  1475. X    theCmap = DefaultColormap (theDisp, theScreen);
  1476. X    rootW = RootWindow (theDisp, theScreen);
  1477. X    theGC = DefaultGC (theDisp, theScreen);
  1478. X    theVisual = DefaultVisual (theDisp, theScreen);
  1479. X    ncells = DisplayCells (theDisp, theScreen);
  1480. X    dispWIDE = DisplayWidth (theDisp, theScreen);
  1481. X    dispHIGH = DisplayHeight (theDisp, theScreen);
  1482. X    dispDEEP = DisplayPlanes (theDisp, theScreen);
  1483. X
  1484. X    __SWM_VROOT = XInternAtom (theDisp, "__SWM_VROOT", False);
  1485. X    XQueryTree (theDisp, rootW, &rootReturn, &parentReturn, &children, 
  1486. X        &numChildren);
  1487. X    for (i = 0;i < numChildren;i++)
  1488. X    {
  1489. X        Atom actual_type;
  1490. X        int actual_format;
  1491. X        unsigned long nitems, bytesafter;
  1492. X        Window *newRoot = NULL;
  1493. X        XWindowAttributes xwa;
  1494. X
  1495. X        if (XGetWindowProperty (theDisp, children [i], __SWM_VROOT, 0, 1, 
  1496. X            False, XA_WINDOW, &actual_type, &actual_format, &nitems, 
  1497. X            &bytesafter, (unsigned char **) &newRoot) == Success && newRoot)
  1498. X        {
  1499. X            rootW = *newRoot;
  1500. X            XGetWindowAttributes (theDisp, rootW, &xwa);
  1501. X            dispWIDE = xwa.width;dispHIGH = xwa.height;
  1502. X            dispDEEP = xwa.depth;
  1503. X            break;
  1504. X        }
  1505. X    }
  1506. X
  1507. X    arrow = XCreateFontCursor (theDisp, XC_top_left_arrow);
  1508. X    target = XCreateFontCursor (theDisp, XC_leftbutton);
  1509. X    hand = XCreateFontCursor (theDisp, XC_hand1);
  1510. X
  1511. X    white = WhitePixel (theDisp, theScreen);
  1512. X    black = BlackPixel (theDisp, theScreen);
  1513. X    if (whitestr && XParseColor (theDisp, theCmap, whitestr, &ecdef) &&
  1514. X        XAllocColor (theDisp, theCmap, &ecdef)) white = ecdef.pixel;
  1515. X    if (blackstr && XParseColor (theDisp, theCmap, blackstr, &ecdef) &&
  1516. X        XAllocColor (theDisp, theCmap, &ecdef)) black = ecdef.pixel;
  1517. X
  1518. X    fg = black;
  1519. X    bg = white;
  1520. X    if (fgstr && XParseColor (theDisp, theCmap, fgstr, &ecdef) &&
  1521. X        XAllocColor (theDisp, theCmap, &ecdef)) fg = ecdef.pixel;
  1522. X    if (bgstr && XParseColor (theDisp, theCmap, bgstr, &ecdef) &&
  1523. X        XAllocColor (theDisp, theCmap, &ecdef)) bg = ecdef.pixel;
  1524. X
  1525. X    rootfg = white;
  1526. X    rootbg = black;
  1527. X    if (rootfgstr && XParseColor (theDisp, theCmap, rootfgstr, &ecdef) &&
  1528. X        XAllocColor (theDisp, theCmap, &ecdef)) rootfg = ecdef.pixel;
  1529. X    if (rootbgstr && XParseColor (theDisp, theCmap, rootbgstr, &ecdef) &&
  1530. X        XAllocColor (theDisp, theCmap, &ecdef)) rootbg = ecdef.pixel;
  1531. X
  1532. X    XSetForeground (theDisp, theGC, fg);
  1533. X    XSetBackground (theDisp, theGC, bg);
  1534. X
  1535. X    infofg = fg;
  1536. X    infobg = bg;
  1537. X
  1538. X    if (!mono)
  1539. X    {
  1540. X        if (theVisual->class == StaticGray || theVisual->class == GrayScale)
  1541. X        mono = 1;
  1542. X    }
  1543. X    if ((mfinfo = XLoadQueryFont (theDisp, FONT))==NULL ||
  1544. X        (bfinfo = XLoadQueryFont (theDisp, BFONT))==NULL)
  1545. X    {
  1546. X        sprintf (str,
  1547. X            "couldn't open the following fonts:\n\t %s \n\t %s", 
  1548. X            FONT, BFONT);
  1549. X        FatalError (str);
  1550. X    }
  1551. X    mfont=mfinfo->fid;
  1552. X    bfont=bfinfo->fid;
  1553. X    SetNormal ();
  1554. X    if (ncols == -1)
  1555. X    {
  1556. X        if (dispDEEP>1) ncols = 1<<dispDEEP;
  1557. X        else ncols = 0;
  1558. X    }
  1559. X    else if (ncols>256) ncols = 256;
  1560. X
  1561. X    CreateDirW (maingeom);
  1562. X
  1563. X    while ((i=EventLoop ()) != QUIT);
  1564. X    Quit (0);
  1565. X    return (0);
  1566. }
  1567. X
  1568. static void Syntax ()
  1569. {
  1570. X    fprintf (stderr, "usage: %s\n", cmd);
  1571. X    fprintf (stderr, "   [-display disp] [-iconic]\n");
  1572. X    fprintf (stderr, "   [-geometry geom] [-icongeom geom]\n");
  1573. X    fprintf (stderr, "   [-bg background] [-fg foreground] [-bw width]\n");
  1574. X    Quit (-1);
  1575. }
  1576. X
  1577. static int EventLoop ()
  1578. {
  1579. X    XEvent event;
  1580. X    int retval, done;
  1581. X
  1582. X    done = retval = 0;
  1583. X    while (!done)
  1584. X    {
  1585. X        if (XPending (theDisp)>0)
  1586. X        {
  1587. X            XNextEvent (theDisp, &event);
  1588. X            switch (event.type)
  1589. X            {
  1590. X                case Expose:
  1591. X                    {
  1592. X                        XExposeEvent *exp_event = (XExposeEvent *) &event;
  1593. X
  1594. X                        ExposureWin (exp_event);
  1595. X                    }
  1596. X                    break;
  1597. X                case ButtonPress:
  1598. X                    {
  1599. X                    XButtonEvent *but_event = (XButtonEvent *) &event;
  1600. X                    int i;
  1601. X
  1602. X                    switch (but_event->button)
  1603. X                    {
  1604. X                        case Button1: 
  1605. X                            if (but_event->window == dirW)
  1606. X                            {
  1607. X                                i=ClickDirW (but_event->x, but_event->y);
  1608. X                                if (i==S_BQUIT) { retval = QUIT;done=1;}
  1609. X                            }
  1610. X                            else if (but_event->window == dList.win)
  1611. X                            {
  1612. X                                i=LSClick (&dList, but_event);
  1613. X                                SelectDir (i);
  1614. X                            }
  1615. X                            else if (but_event->window == dList.scrl.win) 
  1616. X                                SCTrack (&dList.scrl, but_event->x,
  1617. X                                    but_event->y);
  1618. X                            break;
  1619. X                        default:
  1620. X                            break;
  1621. X                    }
  1622. X                }
  1623. X                break;
  1624. X            case KeyPress:
  1625. X                {
  1626. X                XKeyEvent *key_event = (XKeyEvent *) &event;
  1627. X                char buf [128];
  1628. X                KeySym ks;
  1629. X                XComposeStatus status;
  1630. X                int stlen;
  1631. X                stlen = XLookupString (key_event, buf, 128, &ks, &status);
  1632. X                if (!stlen) break;
  1633. X                if (key_event->window == dirW)
  1634. X                    if (DirKey (buf [0])) XBell (theDisp, 0);
  1635. X                }
  1636. X                break;
  1637. X            default:
  1638. X                break;
  1639. X            }
  1640. X        }
  1641. X    }
  1642. X    return (retval);
  1643. }
  1644. X
  1645. /************************************************************************/
  1646. /* following three rd_* functions swiped from xgraph, by David Harrison */
  1647. /************************************************************************/
  1648. X
  1649. static int rd_int (name)
  1650. char *name;
  1651. {
  1652. X    if (def_str = XGetDefault (theDisp, PROGNAME, name))
  1653. X    {
  1654. X        if (sscanf (def_str, "%ld", &def_int) == 1) return 1;
  1655. X        else
  1656. X        {
  1657. X            fprintf (stderr,
  1658. X                "%s: couldn't read integer value for %s resource\n", 
  1659. X                cmd, name);
  1660. X            return 0;
  1661. X        }
  1662. X    }
  1663. X    else return 0;
  1664. }
  1665. X
  1666. static int rd_str (name)
  1667. char *name;
  1668. {
  1669. X    if (def_str = XGetDefault (theDisp, PROGNAME, name)) return 1;
  1670. X    else return 0;
  1671. }
  1672. X
  1673. static int rd_flag (name)
  1674. char *name;
  1675. {
  1676. X    if (def_str = XGetDefault (theDisp, PROGNAME, name))
  1677. X    {
  1678. X        def_int = (strcmp (def_str, "on")==0) || 
  1679. X            (strcmp (def_str, "1")==0) ||
  1680. X            (strcmp (def_str, "true")==0) ||
  1681. X            (strcmp (def_str, "yes")==0);
  1682. X        return 1;
  1683. X    }
  1684. X    else return 0;
  1685. }
  1686. X
  1687. SHAR_EOF
  1688. chmod 0644 xfbrows.c ||
  1689. echo 'restore of xfbrows.c failed'
  1690. Wc_c="`wc -c < 'xfbrows.c'`"
  1691. test 8155 -eq "$Wc_c" ||
  1692.     echo 'xfbrows.c: original size 8155, current size' "$Wc_c"
  1693. fi
  1694. exit 0
  1695.  
  1696. --
  1697. Dan Heller
  1698. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1699. Senior Writer                President          comp-sources-x@uunet.uu.net
  1700. argv@ora.com                 argv@zipcode.com
  1701.